/*
 * Project Name spring-boot-tools
 * File Name ExecytorsUtil
 * Package Name com.huxiaosu.tools.common.executors
 * Create Time 2024/7/9
 * Create by name：liujie
 */
package com.huxiaosu.tools.common.executors;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/9 11:30
 */
public class ExecutorsUtil {
    public static ThreadPoolExecutor createExecutors(){
        //核心线程数
        int corePoolSize = 3;
        //最大线程数
        int maximumPoolSize = 6;
        //超过 corePoolSize 线程数量的线程最大空闲时间
        long keepAliveTime = 2;
        //以秒为时间单位
        TimeUnit unit = TimeUnit.SECONDS;
        //创建工作队列，用于存放提交的等待执行任务
        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(2);
        //创建线程池
        return new ThreadPoolExecutor(corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                unit,
                workQueue,
                new ThreadPoolExecutor.AbortPolicy());
    }
}